package org.mine.design.builder.service.impl;

import org.mine.design.builder.controller.param.RequestParam;
import org.mine.design.builder.enums.CarTypePriceEnum;
import org.mine.design.builder.enums.WeatherPriceEnum;
import org.mine.design.builder.service.CostCalculateService;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
public class ExtraCostCalculateServiceImpl implements CostCalculateService {

    @Override
    public int calculate(RequestParam param) {
        return Arrays.stream(CarTypePriceEnum.values())
                .filter(source -> source.name().equals(param.getCarType()))
                .map(CarTypePriceEnum::getExtraPrice)
                .findFirst()
                .orElse(0) +
                Arrays.stream(WeatherPriceEnum.values())
                        .filter(source -> source.name().equals(param.getWeather()))
                        .map(WeatherPriceEnum::getExtraPrice)
                        .findFirst()
                        .orElse(0);
    }
}
